package com.example.yunbiji0314.service.iml;

import com.example.yunbiji0314.dao.CategoryDao;
import com.example.yunbiji0314.pojo.Category;
import com.example.yunbiji0314.service.CategoryService;
import com.example.yunbiji0314.util.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public PageInfo<Category> findByUserId(PageUtil pageUtil) {
        //设置分页参数
        PageHelper.startPage(pageUtil.getPageNum(), pageUtil.getPageSize());
        //获取用户id
        Integer object = (Integer) pageUtil.getObject();
        //查数据
        List<Category> byUserId = categoryDao.findByUserId(object);
        //引用分页插件
        PageInfo<Category> categoryPageInfo = new PageInfo<>(byUserId);
        return categoryPageInfo;
    }

    @Override
    public int add(Category category) {
        return categoryDao.add(category);
    }

    @Override
    public int delete(Integer id) {
        return categoryDao.delete(id);
    }

    @Override
    public Category findById(Integer id) {
        return categoryDao.findById(id);
    }

    @Override
    public List<Category> selectleixingId(Integer id) {
        return categoryDao.selectleixingId(id);
    }

    @Override
    public List<Category> selectAll() {
        return categoryDao.selectAll();
    }
}
